<%- include("../loaout/header.ejs")%>

<link rel="stylesheet" href="/node_modules/mditor/dist/css/mditor.min.css">
<script src="/node_modules/mditor/dist/js/mditor.min.js"></script>

<div class="container">
  <h1>发表文章页</h1>
  <hr>
  <form id="form">
    <input type="hidden" name="authorid" value="<%=user.id%>">
    <div class="form-group">
      <label>文章标题：</label>
      <input type="text" name="title" class="form-control" required>
    </div>

    <div class="form-group">
      <label>文章内容：</label>
      <textarea name="content" class="form-control" id="editor"></textarea>
    </div>

    <div class="form-group">
      <input type="submit" value="发表文章" class="btn btn-primary">
    </div>
  </form>
</div>
<script>
  $(function () {
    var mditor = Mditor.fromTextarea(document.getElementById('editor'));
    //获取或设置编辑器的值
    // mditor.on('ready', function () {
    //   console.log(mditor.value);
    //   mditor.value = '** hello **';
    // });

    $("form").on("submit",function(e){
        e.preventDefault();
        $.ajax({
          type:"POST",
          url:"/addArticle",
          data:$("form").serialize(),
          success:function(result){
              console.log(result,77);
              if(result.status!=200) return  alert(result.msg);
              location.href="/article/info/"+result.insertId;
          }
        })
    })
  })
</script>

<%- include("../loaout/footer.ejs")%>